Skip to content

Conversation

@G4URAV001
Copy link

@G4URAV001 G4URAV001 commented Apr 25, 2025

📋 Description

Closes PSMRI/AMRIT#88
JIRA ID: issue link

This PR implements commit message linting and automation for all contributors in the API repositories using Commitlint, Husky, and Commitizen. The aim of this initiative is to enforce a consistent and readable commit history, improving collaboration and enabling future automated changelogs and CI/CD processes. This setup aligns with the practices followed across all C4GT Community repositories.

  • Every commit in API repositories will follow the defined structure (e.g., Conventional Commits).

  • Husky will block non-compliant commit messages locally.

  • Contributors will use Commitizen (cz) to follow a guided commit format.

  • GitHub Actions will fail PR checks if commit messages do not follow the required format.

  • All changes will be compatible with the existing CI/CD pipelines, ensuring smooth integration.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

•⁠ ⁠Added ⁠ commitlint.config.js ⁠ with conventional commit rules.
•⁠ ⁠Configured Husky to run Commitlint on every commit via ⁠ .husky/commit-msg ⁠.
•⁠ ⁠Set up ⁠ Commitizen ⁠ with configuration in ⁠ package.json ⁠ for interactive commit prompts.
•⁠ ⁠Added GitHub Actions workflow ⁠ .github/workflows/commit-lint.yml ⁠ to check commit messages on PRs.
•⁠ ⁠Updated ⁠ package.json ⁠ and ⁠ package-lock.json ⁠ with required dev dependencies:

  • ⁠ @commitlint/cli ⁠
    ⁠ - @commitlint/config-conventional ⁠
    ⁠ - commitizen ⁠
    ⁠ - cz-conventional-changelog ⁠

Testing & Validation
•⁠ ⁠Invalid commit messages are blocked locally with clear lint errors.
•⁠ ⁠Interactive commit flow works via ⁠ npm run commit ⁠ or ⁠ npx cz ⁠.
•⁠ ⁠GitHub Actions workflow correctly fails PRs with non-compliant commit messages.
•⁠ ⁠No disruption to existing build or CI pipelines.
Screenshot 2025-04-25 213042
Screenshot 2025-04-25 213052

Summary by CodeRabbit

  • New Features

    • Introduced automated commit message linting for pull requests to ensure message consistency.
    • Added Git hooks to enforce commit message standards during local development.
    • Provided standardized tools and scripts for creating properly formatted commit messages.
  • Documentation

    • Updated the README with instructions for setting up commit hooks and guidelines for commit message formatting.
  • Chores

    • Updated ignore rules to exclude Node.js dependencies and logs from version control.

@coderabbitai
Copy link

coderabbitai bot commented Apr 25, 2025

Walkthrough

This change introduces a standardized commit message enforcement system into the project. It adds configuration and tooling for commit message linting using Commitlint, integrates Husky for Git hooks, and sets up Commitizen for guided commit creation. A GitHub Actions workflow is added to automatically validate commit messages on pull requests. The .gitignore is updated for Node.js conventions, and documentation is expanded with setup instructions and commit message guidelines. New configuration files and scripts are included to support these tools and workflows.

Changes

File(s) Change Summary
.github/workflows/commit-lint.yml Added a GitHub Actions workflow to lint commit messages on pull request events using Commitlint.
.gitignore Added Node.js-specific ignore rules for node_modules/ and npm-debug.log.
.husky/commit-msg Added Husky Git hook script to lint commit messages during the commit process.
README.md Added detailed instructions for setting up commit hooks, commit message conventions, and Commitizen usage. Minor formatting fix.
commitlint.config.js Added Commitlint configuration enforcing Conventional Commits specification and custom rules.
package.json Added project metadata, npm scripts, Commitizen config, and devDependencies for Commitlint, Commitizen, Husky, and related tooling.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Husky
    participant Commitlint
    participant GitHub Actions

    Developer->>Husky: git commit
    Husky->>Commitlint: Lint commit message
    Commitlint-->>Husky: Pass/Fail
    Husky-->>Developer: Allow/Block commit

    Developer->>GitHub Actions: Open/sync PR
    GitHub Actions->>Commitlint: Lint commits in PR
    Commitlint-->>GitHub Actions: Pass/Fail
    GitHub Actions-->>Developer: Status check result
Loading

Possibly related issues

Poem

In the garden of code where rabbits hop,
Commit messages now never flop!
With Husky and friends at every gate,
Linting your words before it’s too late.
GitHub checks each pull request—
Only the best messages pass the test.
Hippity-hop, our history’s neat—
Conventional commits make it sweet!

((\
( -.-)
o_(")(")

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🔭 Outside diff range comments (1)
README.md (1)

9-11: ⚠️ Potential issue

Fix hyperlink formatting
The extra space breaks the Markdown link syntax, so the URL won’t render as a link.

- Find the detailed list of software dependencies [here] (https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup/software-dependencies) .
+ Find the detailed list of software dependencies [here](https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup/software-dependencies).
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

10-10: Bare URL used
null

(MD034, no-bare-urls)

🧹 Nitpick comments (5)
.gitignore (1)

31-31: Scope the local properties ignore to its directory
Using bengen_local.properties alone will match any file with that name. To avoid unintentionally ignoring files elsewhere, specify the path:

- bengen_local.properties
+ src/main/environment/bengen_local.properties
.github/workflows/commit-lint.yml (1)

25-27: Speed up CI by caching npm modules
Installing dependencies on every run can be slow. Consider caching the npm cache between jobs:

-      - name: Install dependencies
-        run: npm ci --legacy-peer-deps
+      - name: Cache npm modules
+        uses: actions/cache@v3
+        with:
+          path: ~/.npm
+          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
+          restore-keys: |
+            ${{ runner.os }}-node-
+
+      - name: Install dependencies
+        run: npm ci --legacy-peer-deps
package.json (1)

10-12: Use module name for Commitizen adapter path
Referencing the package by name improves maintainability and avoids path issues:

-    "path": "./node_modules/cz-conventional-changelog"
+    "path": "cz-conventional-changelog"
README.md (1)

43-46: Specify language for fenced code blocks
Adding a language identifier (e.g., bash, sh) enables syntax highlighting and improves readability.

- ```
+ ```bash
     node --version
     npm --version
- ```
+ ```

Apply the same change to the other code fences in this section.

Also applies to: 50-52, 82-84

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

43-43: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

commitlint.config.js (1)

16-34: Commit type constraints are comprehensive
type-case, type-empty, and type-enum restrict commit types to lowercase and a well-defined set. Consider optionally adding scope-case: [2, 'always', 'lower-case'] or scope-empty: [2, 'never'] if you want to enforce consistent scope usage across commits.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8aa4193 and f5b995c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • .github/workflows/commit-lint.yml (1 hunks)
  • .gitignore (1 hunks)
  • .husky/commit-msg (1 hunks)
  • README.md (2 hunks)
  • commitlint.config.js (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/commit-lint.yml

[error] 30-30: no new line character at the end of file

(new-line-at-end-of-file)


[error] 30-30: trailing spaces

(trailing-spaces)

🪛 LanguageTool
README.md

[uncategorized] ~41-~41: The official spelling of this programming framework is “Node.js”.
Context: ...d npm** - Download and install from nodejs.org - Verify i...

(NODE_JS)


[grammar] ~67-~67: “Bug” is a singular noun. It appears that the verb form is incorrect.
Context: ... - feat: A new feature - fix: A bug fix - docs: Documentation changes - `styl...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[uncategorized] ~70-~70: Loose punctuation mark.
Context: ... changes (formatting, etc.) - refactor: Code changes that neither fix bugs nor ...

(UNLIKELY_OPENING_PUNCTUATION)

🪛 markdownlint-cli2 (0.17.2)
README.md

35-35: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


36-36: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


41-41: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


42-42: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


43-43: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


49-49: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


50-50: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


53-53: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


56-56: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


57-57: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


62-62: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


63-63: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


66-66: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


67-67: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


68-68: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


69-69: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


70-70: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


71-71: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


72-72: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


73-73: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


74-74: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


75-75: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


82-82: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🔇 Additional comments (3)
commitlint.config.js (3)

1-3: Extends conventional commit rules
The extends field correctly pulls in @commitlint/config-conventional to enforce standard commit conventions.


4-8: Validate body and footer formatting
Rules for body-leading-blank, body-max-line-length, footer-leading-blank, footer-max-line-length, and header-max-length are set with appropriate severity and line-length caps.


9-15: Enforce subject style
The subject-case, subject-empty, and subject-full-stop rules ensure subjects are concise, non-empty, and without trailing periods.

@@ -0,0 +1 @@
npx --no -- commitlint --edit $1 No newline at end of file
Copy link

@coderabbitai coderabbitai bot Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure Husky hook loads correctly and has valid shebang
The hook currently only calls npx --no -- commitlint --edit $1 without a shebang or sourcing Husky’s loader. Without these, the script might not execute properly in the Git hook context.

Apply this diff:

- npx --no -- commitlint --edit $1 
+ #!/usr/bin/env sh
+ . "$(dirname "$0")/_/husky.sh"
+ npx --no-install commitlint --edit "$1"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
npx --no -- commitlint --edit $1
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit "$1"

Copy link
Author

@G4URAV001 G4URAV001 Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to point out that the shebang (#!/usr/bin/env sh) and the sourcing of the Husky helper script (. "$(dirname "$0")/_/husky.sh") are now deprecated.

As of Husky v9.1.1, these lines are automatically removed during installation, and they will fail in Husky v10.0.0.

For compatibility with future versions of Husky, it’s recommended to remove these lines from the hook script.

The message from husky.sh -

echo "husky - DEPRECATED

Please remove the following two lines from $0:

#!/usr/bin/env sh
. \"\$(dirname -- \"\$0\")/_/husky.sh\"

They WILL FAIL in v10.0.0
"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@G4URAV001 You're absolutely right. The --no flag is incorrect, and --no-install is the proper flag to prevent npx from installing packages if they're not found locally. Quoting the $1 parameter is also good practice to handle filenames with spaces correctly.

The suggested change looks good:

npx --no-install commitlint --edit "$1"

✏️ Learnings added
Learnt from: G4URAV001
PR: PSMRI/BeneficiaryID-Generation-API#33
File: .husky/commit-msg:1-1
Timestamp: 2025-04-25T16:51:01.946Z
Learning: When using npx with commitlint in Git hooks, the correct flag to prevent automatic installation is `--no-install` (not `--no`), and the commit file parameter ($1) should be quoted as "$1" to handle filenames with spaces properly.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


- name: Run commitlint on PR
run: |
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose No newline at end of file
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add newline at EOF and remove trailing spaces
YAML requires a newline at end-of-file and no trailing spaces; otherwise, the workflow may fail to parse.

-          npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose 
+          npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 30-30: no new line character at the end of file

(new-line-at-end-of-file)


[error] 30-30: trailing spaces

(trailing-spaces)

Comment on lines +5 to +7
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky",
"commit": "cz"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify Husky installation command
The prepare script uses husky, but the recommended command is husky install. Please confirm that running npm run prepare correctly sets up the .husky directory.

Run:

Ensure the hooks directory and scripts are installed.


🏁 Script executed:

npm run prepare
ls -la .husky

Length of output: 280


Update prepare script to use husky install
Running npm run prepare currently errors with “husky: not found,” so the hooks aren’t being initialized correctly. Change the prepare script in package.json to invoke husky install.

• File: package.json
• Lines: 5–7

Suggested diff:

     "test": "echo \"Error: no test specified\" && exit 1",
-    "prepare": "husky",
+    "prepare": "husky install",
     "commit": "cz"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky",
"commit": "cz"
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky install",
"commit": "cz"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C4GT Community]: Implement Commit Message Linting and Automation for BeneficiaryID-Generation-API

1 participant